<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes" />
  <xsl:template match="/Prints">

    <script type="text/javascript">
      var firstItem = true;
      var insertBr = false;
      var currentYear = 0;
      
      function writeYear(input){
        if (currentYear != input){
          if (firstItem != true){
            document.write("<br/><br/>");
          }
          document.write("<h3>" + input + "</h3><br />");
          currentYear = input;
          firstItem = false;
        }
      }
    </script>
    
    
    <xsl:for-each select="print">
      <xsl:sort select="sortdate" data-type="number" order="descending" />
      <script type="text/javascript">
        writeYear(<xsl:value-of select="substring(sortdate, 0,5)"/>);
      </script>
      
      <p>
        <a target="_blank">
          <xsl:attribute name="href">
            <xsl:value-of select="link" />
          </xsl:attribute>
          <xsl:element name="img">
            <xsl:attribute name="src">
              <xsl:if test="icon='PDF'">asset/images/icpdf.gif</xsl:if>
              <xsl:if test="icon='Webpage'">asset/images/icpdf.gif</xsl:if>
              <xsl:if test="icon='JPG'">asset/images/icgif.gif</xsl:if>
            </xsl:attribute>
          </xsl:element>
          <xsl:value-of select="title" disable-output-escaping="yes" /> - <xsl:value-of select="source" /> (<script>
            document.write(dateFormat("<xsl:value-of select="date" />", "mmmm dd yyyy"))
          </script>)
        </a>
      </p>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>